﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YNCNumberSys.db;

namespace YNCNumberSys.DbDal
{
    public class InitDal
    {
        private CommandManager commandManager = new CommandManager();
        private ConnectionManager connectionManager = new ConnectionManager();
       public DataTable GetIninitDatable()
        {
            string sql = string.Format(@"SELECT [0J]
                                              ,[1J]
                                              ,[2J]
                                              ,[3J]
                                              ,[4J]
                                              ,[0L]
                                              ,[1L]
                                              ,[2L]
                                              ,[3L]
                                              ,[4L]
                                              ,[0D]
                                              ,[1D]
                                              ,[2D]
                                              ,[3D]
                                              ,[4D]
                                              ,[0Z]
                                              ,[1Z]
                                              ,[2Z]
                                              ,[3Z]
                                              ,[4Z]
                                              ,[4C]
                                          FROM [YNCNumberSys].[dbo].[初始编码]; ");
            return commandManager.ExecuteNonQuery(connectionManager.getConnection(), sql, "初始编码");
        }

        public DataTable GetIninitEmptyDatable()
        {
            string sql = string.Format(@"SELECT [0J]
                                              ,[1J]
                                              ,[2J]
                                              ,[3J]
                                              ,[4J]
                                              ,[0L]
                                              ,[1L]
                                              ,[2L]
                                              ,[3L]
                                              ,[4L]
                                              ,[0D]
                                              ,[1D]
                                              ,[2D]
                                              ,[3D]
                                              ,[4D]
                                              ,[0Z]
                                              ,[1Z]
                                              ,[2Z]
                                              ,[3Z]
                                              ,[4Z]
                                              ,[4C]
                                          FROM [YNCNumberSys].[dbo].[初始编码] where 1=2; ");
            return commandManager.ExecuteNonQuery(connectionManager.getConnection(), sql, "初始编码");
        }
        public int UpdateIninitDatable(DataTable dt)
        {
            string sql = "Update [YNCNumberSys].[dbo].[初始编码] set ";
            for(int i=0;i< dt.Columns.Count;i++)
            {
                string s = string.Format("[{0}]={1}", dt.Columns[i].ColumnName, dt.Rows[0][i]);
                if(i< dt.Columns.Count-1)
                  sql = sql+ s + ",";
                else
                    sql = sql + s;
            }
            return commandManager.ExecuteScalar(connectionManager.getConnection(), sql);
        }

    }
}
